from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from options import options
from service import service

url=r"http://www.baidu.com"
dr=webdriver.Chrome(options=options,service=service)
dr.get(url)
dr.maximize_window()
sleep(1)
# 1、id定位
# dr.find_element(By.ID,'kw').send_keys('python')
# dr.find_element(By.ID,'su').click()
# sleep(3)
# # 2、name定位
# dr.find_element(By.NAME,'wd').send_keys('的用法')
# dr.find_element(By.ID,'su').click()
# sleep(3)
# # 3、tag标签定位
# dr.find_elements(By.TAG_NAME,'input')[7].send_keys('和技巧')
# dr.find_element(By.ID,'su').click()
# sleep(3)
# # 4、class定位
# dr.find_element(By.CLASS_NAME,'s_ipt').send_keys('2222')
# dr.find_element(By.CLASS_NAME,'bg.s_btn').click()
# sleep(3)
# # 5、XPATH定位(相对路径)
# dr.find_element(By.XPATH,'//*[@id="kw"]').send_keys('11111')
# dr.find_element(By.XPATH,'//*[@id="su"]').click()
# sleep(3)
# 5.1 XPATH相对路径--指定标签
# dr.find_element(By.XPATH,'//input[@id="kw"]').send_keys('aaaaa')
# dr.find_element(By.XPATH,'//input[@id="su"]').click()
# sleep(3)
# 5.2 XPATH相对路径--指定上层元素的路径
# dr.find_element(By.XPATH,'//form[@id="form"]/span/input[@id="kw"]').send_keys('qqqq')
# dr.find_element(By.XPATH,'//form[@id="form"]/span/input[@id="su"]').click()
# sleep(3)
# 5.3 XPATH相对路径--指定多个属性（属性的逻辑运算）
# dr.find_element(By.XPATH,'//*[@name="wd" and @id="kw"]').send_keys('zzzzz')
# dr.find_element(By.XPATH,'//*[@id="su"]').click()
# sleep(3)
# 6、css定位
# dr.find_element(By.CSS_SELECTOR,'#kw').send_keys('33333')
# dr.find_element(By.CSS_SELECTOR,'#su').click()
# sleep(3)
# 6.1 css--class选择器
# dr.find_element(By.CSS_SELECTOR,'.s_ipt').send_keys('lol')
# dr.find_element(By.CSS_SELECTOR,'.bg.s_btn').click()
# sleep(3)
# 6.2 css--使用其他属性
# dr.find_element(By.CSS_SELECTOR,'[id="kw"]').send_keys('cf')
# dr.find_element(By.CSS_SELECTOR,'[id="su"]').click()
# sleep(3)
# 6.3 css--使用多个属性
# dr.find_element(By.CSS_SELECTOR,'#kw.s_ipt[id="kw"][name="wd"]').send_keys('dnf')
# dr.find_element(By.CSS_SELECTOR,'#su.bg.s_btn[type="submit"][id="su"]').click()
# sleep(3)
# 6.4 css--使用层级
dr.find_element(By.CSS_SELECTOR,'form[id="form"]>span>input[id="kw"]').send_keys('cs')
dr.find_element(By.CSS_SELECTOR,'form[name="f"]>span>input[type="submit"]').click()
sleep(3)
# # 7、link链接定位
# dr.find_element(By.LINK_TEXT,'图片').click()
# sleep(3)
# # 8、partial_link部分链接定位
# dr.find_element(By.PARTIAL_LINK_TEXT,'最').click()
# sleep(3)

dr.quit()